<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/config.jsp" %>
<html>
<head>
</head>
<body>
<center>
    <form action="query.jsp" method="post">
        请输入学号：<input type="text" name="sno">
        请输入姓名:<input type="text" name="name">
        请选择班级：<select name="clazz">
        <option value="">全部</option>
        <option value="18电子商务技术1班">18电子商务技术1班</option>
        <option value="18电子商务技术2班">18电子商务技术2班</option>
        <option value="18计算机应用技术（数据应用）">18计算机应用技术（数据应用）</option>
    </select>
        <input type="submit" value="查询">
    </form>
    <input type="button" value="添加" onclick="add();">
    <table border="1px" width="930px">
        <tr>
            <td width="30px">
                <input type="checkbox" id="checkAll">全选
            </td>
            <td width="150px">学号</td>
            <td width="150px">姓名</td>
            <td width="300px">班级</td>
            <td width="200px">操作</td>
        </tr>
        <%
            //4、创键sql命令（给司机下指令）
            String sql = "select * from t_user where 1=1 ";
            String sno = request.getParameter("sno");
            if (sno != null && !"".equals(sno)) {
                sql = sql + " AND  id like '%" + sno + "%'";
            }
            String name = request.getParameter("name");
            if (name != null && !"".equals(name)) {
                sql = sql + " AND name like '%" + name + "%'";
            }
            String clazz = request.getParameter("clazz");
            if (clazz != null && !"".equals(clazz)) {
                sql = sql + " AND clazz = '" + clazz + "'";
            }
            //5、执行命令（司机去拉货）
            ResultSet rs = stmt.executeQuery(sql);
            //6、处理结果集（卸货）
            while (rs.next()) {
                String id = rs.getString("id");
                out.print("<tr>");
                out.print("<td>");
                out.print("<input type=\"checkbox\">");
                out.print("</td>");
                out.print("<td>");
                out.print(rs.getString("id"));
                out.print("</td>");
                out.print("<td>");
                out.print(rs.getString("name"));
                out.print("</td>");
                out.print("<td>");
                out.print(rs.getString("clazz"));
                out.print("</td>");
                out.print("<td>");
                out.print("<a href='update.jsp?id="+id+"'>修改</a>|");
                out.print("<a href='javascript:del(\"" + id + "\")'>删除</a>|");
                out.print("|<a href='view.jsp?id=" + id + "'>查看详情</a>");
                out.print("</td>");
                out.print("</tr>");

            }
            //7、关闭资源（卸磨杀驴）
            conn.close();
        %>
    </table>
</center>
<script type="application/javascript">

    function del(id) {
        if (confirm("你是否要删除学号为" + id + "的同学吗？")) {
            window.location = "delete.jsp?id=" + id;
        } else {
            alert("你取消了删除学号为" + id + "的同学");
        }
    }

    function add() {
        window.location = "add.jsp";
    }
</script>


</body>
</html>

<%--MySQL:
驱动名称：com.mysql.jdbc.Driver
连接字符串：jdbc:mysql://127.0.0.1:3306/12006242601

SQL Server:
驱动名称：com.microsoft.sqlserver.jdbc.SQLServerDriver
连接字符串：jdbc:sqlserver://127.0.0.1:1433;DatabaseName=12006242601

Oracle:
驱动名称：oracle.jdbc.driver.OracleDriver
连接字符串：jdbc:oracle:thin:@127.0.0.1:1521:ZHLI2008

SQLite:
驱动名称：org.sqlite.JDBC
连接字符串：jdbc:sqlite:c:/12006242601.db
--%>


